package com.example.demo.service;

import com.example.demo.entity.UserInfo;
import com.example.demo.repository.UesrInfoRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserService {

    @Resource
    private UesrInfoRepository uiRepo;

    public void addUser(String name, Integer age, String password) {
        UserInfo ui = new UserInfo();
        ui.setName(name);
        ui.setAge(age);
        ui.setPassword(password);
        uiRepo.save(ui);
    }

    public List<UserInfo> getAllUsers() {
        return uiRepo.findAll();
    }


    public UserInfo getUserByName(String name) {
        return uiRepo.findFirstByNameOrderByIdAsc(name);
    }

}
